Skip to content

Studio on Windows: recommend Repair when an existing home is older than the managed torch / xFormers - #19870

Merged
danielhanchen merged 13 commits into
mainfrom
g103-studio-repair-hint
Nov 27, 2026
Merged

danielhanchen merged 13 commits into
mainfrom
g103-studio-repair-hint

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Problem

An existing Windows home keeps the torch it was installed with. Only Repair (which sets UNSLOTH_TORCH_UPGRADE=1) moves it to the managed build (install.ps1 Cu130NewInstallTorchSpec, torch 2.13). RTX 50-series (sm_120) support is built and tested on that torch, and nothing in the app says that an older home there would be moved onto it by Repair.

Fix

  • New utils/hardware/windows_repair.py, torch-free: package metadata plus the cached nvidia-smi compute-capability query, so the polled route can call it. windows_repair_recommendation() returns {reason, torch, managed_torch} when all of these hold:

    • the platform is win32;
    • torch is a CUDA build (+cu);
    • an sm_120+ card is present;
    • torch is older than 2.13 (torch_older_than_managed).

    The xFormers version is never a reason. The managed 0.0.35 cu130 wheel builds no FlashAttention 2 of its own, and its cutlass kernels stop at sm_90, so on sm_120 it is not an upgrade over an installed 0.0.34 (whose FA2 comes from the flash_attn package).

    It also requires that Repair can reach the managed torch: install.ps1's 2.13 route (Test-Cu130Torch213Platform) is x64 with a Python 3.13 venv on the cu130 index, and Repair builds that venv with UNSLOTH_PYTHON when set, else 3.13. Off that route it returns None. A driver whose nvidia-smi header reports CUDA below 13.0 gets driver_older_than_managed, and the hint asks for a driver update before Repair, since Repair alone would keep the old torch.

    It returns None otherwise.

  • /api/system gets the additive key repair_recommendation (null otherwise).

  • Desktop Settings > Repair installation shows a "Repair recommended: ..." line under the row with the installed and managed versions. It appears only where the Repair action exists (Desktop, not an external server).

Tests

  • studio/backend/tests/test_windows_repair_recommendation.py (30 tests):
    • Recommends: an old torch on RTX 50, with no xFormers field or version in the payload; a mixed host with one RTX 50 card.
    • Never recommends xFormers: the managed torch with xFormers 0.0.34, 0.0.33.post2 or none gives no recommendation (this test fails on the previous head, which offered 0.0.35).
    • Asks for a driver update first: a driver below CUDA 13. The nvidia-smi header is parsed as install.ps1 reads it, and the route gate is checked against install.ps1.
    • Does not recommend: off the managed route (Windows on ARM, another venv Python), the managed pair, a newer torch, an RTX 40 card, no readable card, a CPU wheel, no torch, Linux, macOS.
    • The 2.13 floor is read back from install.ps1, so bumping the pin there fails the test until the floor is bumped too.
    • The route returns null when the probe fails.
  • studio/frontend/tests/repair-recommendation.test.ts: all three wordings render with no leftover placeholders, nothing renders for null or an unknown reason, and the Repair row renders the hint with the hook called before the early return.
  • i18n parity check passes. Related frontend tests (40) and the backend tests that read /api/system (604) pass.

Not covered here: the hint on a real RTX 50-series Windows install with an old home.

…an the managed torch / xFormers

An existing home keeps the torch it was installed with; only Repair moves it to the managed build. On RTX 50-series cards xFormers trains only with torch 2.13 and xFormers 0.0.35, so /api/system now reports repair_recommendation (torch-free: package metadata and the cached nvidia-smi capability query) for a Windows CUDA install with an sm_120+ card and an older torch or xFormers, and the Desktop Repair row shows a 'Repair recommended' line under it.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T06:40:51.620963Z 5e4e149 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c49e733cf2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +63 to +64
if torch_release is not None and torch_release[:2] < WINDOWS_MANAGED_TORCH_FLOOR:
reason = "torch_older_than_managed"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate the recommendation on eligibility for the managed torch route

On an RTX 50-series Windows host whose driver reports CUDA 12.8, this recommends Repair even though Repair cannot install the advertised PyTorch 2.13. In install.ps1, driver-based selection chooses cu128 (lines 9717–9718), whereas Test-Cu130Torch213Platform allows the 2.13 route only for cu130 with Python 3.13 (lines 9950–9960); otherwise the installer retains its default torch>=2.4,<2.12.0 constraint. Consequently, even a successfully repaired installation keeps showing this recommendation, sending users through a lengthy reinstall without resolving it. Check the managed route's prerequisites before recommending Repair, or explain the required driver upgrade instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7ceae54: the recommendation now follows Test-Cu130Torch213Platform. Off x64 with the Python 3.13 venv there is none. When the driver (nvidia-smi header, read as install.ps1 reads it) does not support CUDA 13, the reason is driver_older_than_managed and the hint asks for a driver update first, then Repair. An unreadable driver still recommends Repair. Covered by test_a_driver_too_old_for_the_managed_route_asks_for_a_driver_update_first, test_a_host_off_the_managed_route_gets_no_recommendation, and a test that the gate matches install.ps1.

…e managed torch

install.ps1 installs torch 2.13 only through the cu130 index on x64 with the Python 3.13 venv. Off that route there is no recommendation; a driver that does not support CUDA 13 gets a driver-update-first hint instead, since Repair alone would keep the old torch.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ceae54b34

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


def _managed_route_host() -> bool:
"""install.ps1's 2.13 route (Test-Cu130Torch213Platform): x64 Windows with the Python 3.13 venv."""
return _platform.machine().lower() in ("amd64", "x86_64") and sys.version_info[:2] == (3, 13)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check the Python version Repair will select, not the running venv

On an x64 Windows installation still using Python 3.11 or 3.12, with an RTX 50-series GPU and a CUDA 13-capable driver, this suppresses the recommendation even though Repair can install the managed pair. The desktop installer sets UNSLOTH_TORCH_UPGRADE=1 (studio/src-tauri/src/install.rs), and install.ps1:1863–1870,6214–6226 consequently selects the default Python 3.13 rather than preserving the existing minor; it then replaces the current venv. Checking the running interpreter therefore excludes older homes that Repair would actually upgrade. Base eligibility on the interpreter Repair will select, while respecting an explicit Python override.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8e2ada6: the route gate now uses the Python a Repair selects, UNSLOTH_PYTHON when set, else 3.13 (install.ps1 does not keep the existing minor under UNSLOTH_TORCH_UPGRADE=1), instead of the running interpreter. Covered by test_repair_builds_its_venv_with_the_python_install_ps1_selects.

…e running venv

Under UNSLOTH_TORCH_UPGRADE=1 install.ps1 builds the venv with UNSLOTH_PYTHON when set, else 3.13, so a 3.11 / 3.12 home that Repair moves to 3.13 is now recommended.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e2ada6f0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +79 to +81
def _managed_route_host() -> bool:
"""install.ps1's 2.13 route (Test-Cu130Torch213Platform): x64 Windows, and the venv Repair builds is 3.13."""
return _platform.machine().lower() in ("amd64", "x86_64") and _repair_python_minor() == "3.13"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor explicit torch index overrides in the route gate

On an x64 Windows RTX 50-series host with a CUDA 13-capable driver and UNSLOTH_TORCH_INDEX_FAMILY=cu128 (or UNSLOTH_TORCH_INDEX_URL pointing to cu128), this still recommends Repair to obtain torch 2.13. However, install.ps1's Get-TorchIndexUrl honors these overrides before driver-based selection, and Test-Cu130Torch213Platform rejects any index whose leaf is not cu130. These variables are inherited by the desktop installer, so Repair cannot reach the advertised version and the recommendation persists after reinstalling. Include the effective index override in the eligibility check, or explain that the override must be changed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fb89fd7: UNSLOTH_TORCH_INDEX_URL (its leaf, as Get-TorchIndexLeafName reads it) or UNSLOTH_TORCH_INDEX_FAMILY pinning anything but cu130 now closes the route, so no recommendation is shown. Covered by test_an_index_override_off_cu130_closes_the_route.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb89fd7a23

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +63 to +65
errors = "replace",
timeout = 5,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Hide the driver-probe subprocess on Windows

On a Windows desktop installation with an outdated torch/xFormers pair and an RTX 50-series GPU, the first /api/system request reaches this probe. Unlike get_compute_capabilities() in utils/hardware/nvidia.py, this invocation omits windows_hidden_subprocess_kwargs(), and gpu_query.run_nvidia_smi() forwards the arguments directly to subprocess.run without adding window-suppression flags. Because the desktop backend runs without a console, this creates a visible console window during an otherwise background status request. Pass the existing hidden-subprocess kwargs here as the other NVIDIA probes do.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in df67a70: the probe now passes windows_hidden_subprocess_kwargs() and child_env_without_native_path_secret(), as nvidia.py's queries do; the parsing test asserts the hidden-window flags reach the call.

…idia-smi queries

No console window on Windows and no native-path secret in its environment.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 27, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: df67a702eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ts own

The managed xFormers 0.0.35 cu130 wheel builds no FlashAttention 2 of its own and its cutlass kernels stop at sm_90, so on an RTX 50-series card it is not an upgrade over an installed 0.0.34. The hint now keys on torch alone: no xformers_older_than_managed reason, no xFormers versions in the payload or the wording.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 1aceba7774

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…r nvidia-smi header spelling

Newer drivers (616.56 on an RTX 5090) print 'CUDA UMD Version: 13.4' instead of 'CUDA Version:', so the driver check read None there. The regex now matches both, as install.ps1's already does.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03c5e739ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +99 to +101
_platform.machine().lower() in ("amd64", "x86_64")
and _repair_python_minor(environ) == "3.13"
and leaf in (None, "cu130")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Account for the installer's package-index route gate

On an x64 Windows RTX 50-series host with an older CUDA torch and a CUDA 13-capable driver, setting UV_INDEX_URL to a package mirror still produces the Repair recommendation. However, install.ps1's Test-PypiUnslothAdmitsTorch explicitly returns false when Test-MirrorConfigured -Tool uv detects that variable; Resolve-Cu130TorchRoute consequently leaves NewInstall false and installation retains the default torch>=2.4,<2.12.0 constraint. Repair therefore cannot deliver the advertised 2.13 upgrade, and the recommendation persists after reinstalling. Include the installer's deterministic package-index restrictions in this eligibility check, or explain the configuration change required before recommending Repair.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5a046a6: the route gate now applies Test-PypiUnslothAdmitsTorch's deterministic refusals: UV_OFFLINE, UV_EXCLUDE_NEWER / UV_EXCLUDE_NEWER_PACKAGE, a uv mirror in UV_DEFAULT_INDEX / UV_INDEX_URL / UV_INDEX / UV_EXTRA_INDEX_URL, or an index line in UV_CONFIG_FILE / %APPDATA%\uv\uv.toml / %ProgramData%\uv\uv.toml (same pattern as Test-MirrorConfigured -Tool uv). Under any of these there is no recommendation. Covered by test_a_package_mirror_or_offline_uv_closes_the_route, test_an_index_in_the_uv_config_file_closes_the_route, and a check against install.ps1.

… managed route

install.ps1's Test-PypiUnslothAdmitsTorch refuses the torch 2.13 route under UV_OFFLINE, an exclude-newer cutoff, or a uv package mirror (environment or uv.toml), so Repair would keep the old torch there; the hint now applies the same gates.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a046a6a12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +104 to +107
if environ.get("UV_CONFIG_FILE"):
files.append(environ["UV_CONFIG_FILE"])
if environ.get("APPDATA"):
files.append(os.path.join(environ["APPDATA"], "uv", "uv.toml"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor uv configuration precedence when checking mirrors

On an otherwise eligible Windows RTX 50-series installation, a mirror in the user-level uv.toml suppresses the Repair recommendation even when UV_NO_CONFIG=1 disables that file or UV_CONFIG_FILE selects a different, mirror-free configuration. _uv_config_files() always includes the user and system files, whereas install.ps1's Test-MirrorConfigured explicitly makes UV_CONFIG_FILE exclusive and skips configuration discovery under UV_NO_CONFIG. Repair can therefore reach the managed torch in these cases, but the user receives no upgrade hint. Apply the same configuration precedence before inspecting files.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c55eba0: _uv_config_files now follows Test-MirrorConfigured: UV_CONFIG_FILE alone (even with UV_NO_CONFIG), none under UV_NO_CONFIG, else the user file plus the system file unless UV_NO_SYSTEM_CONFIG. Project discovery walks the installer's working directory, which the backend cannot know, so it is not mirrored. Covered by test_uv_config_precedence_follows_install_ps1.

…cedence

UV_CONFIG_FILE is exclusive and UV_NO_CONFIG skips discovery, as Test-MirrorConfigured does.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c55eba0440

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

and str(environ.get("UV_NO_SYSTEM_CONFIG", "")).strip().lower() not in _UV_TRUE
):
files.append(os.path.join(environ["ProgramData"], "uv", "uv.toml"))
return files

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include explicitly selected project configs in the mirror gate

On an otherwise eligible Windows RTX 50-series host, setting UV_PROJECT to an absolute directory containing a mirror-configured uv.toml still produces the Repair recommendation: this helper only returns user/system configs and ignores the selected project. In the inspected Windows installer, Test-MirrorConfigured resolves UV_PROJECT and discovers its configuration (install.ps1:4215–4222), causing Test-PypiUnslothAdmitsTorch to reject the 2.13 route. Repair therefore retains the old torch window and the recommendation persists. Include explicitly selected project configurations in this check; an absolute UV_PROJECT does not require knowing the installer's working directory.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen Nov 27, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 24cbe58 (my earlier reply named the wrong commit; the change had not been pushed yet). With UV_PROJECT set, and no UV_CONFIG_FILE or UV_NO_CONFIG, the gate walks up from that project like install.ps1: resolved against UV_WORKING_DIR / UV_WORKING_DIRECTORY, it reads the first uv.toml or pyproject.toml with [tool.uv. Covered by test_an_explicit_uv_project_config_closes_the_route.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: c55eba0440

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ects in the mirror gate

install.ps1's Test-MirrorConfigured walks up from UV_PROJECT (resolved against UV_WORKING_DIR) to the first uv.toml or [tool.uv] pyproject.toml; the gate now reads the same file.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 27, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 24cbe58489

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	studio/backend/main.py

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 339128dbea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +120 to +122
if environ.get("UV_PROJECT"):
base = environ.get("UV_WORKING_DIR") or environ.get("UV_WORKING_DIRECTORY") or os.getcwd()
directory = os.path.abspath(os.path.join(base, environ["UV_PROJECT"]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Discover configs selected by UV_WORKING_DIR without UV_PROJECT

On an otherwise eligible Windows RTX 50-series installation, setting UV_WORKING_DIR (or UV_WORKING_DIRECTORY) to an absolute directory containing a mirror-configured uv.toml, without setting UV_PROJECT, still produces the Repair recommendation. This condition skips project discovery entirely, whereas install.ps1's Test-MirrorConfigured starts discovery from the working-directory override even without UV_PROJECT (install.ps1:4273–4287). The installer consequently rejects the managed 2.13 route and Repair retains the older torch window, leaving the recommendation unresolved. Start discovery from an explicit working-directory override as well as an explicit project.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 84ee157: discovery now starts from UV_WORKING_DIR / UV_WORKING_DIRECTORY even without UV_PROJECT, and UV_PROJECT and UV_CONFIG_FILE resolve against it, matching Test-MirrorConfigured. New test covers both spellings and fails on 339128d.

….ps1 does

install.ps1's mirror check walks up from the working-directory override
even without UV_PROJECT and resolves UV_PROJECT and UV_CONFIG_FILE
against it. Do the same, so a mirror in that directory's uv.toml is seen
and the hint is not shown when Repair cannot reach the managed torch.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84ee157356

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +123 to +124
if work_dir or environ.get("UV_PROJECT"):
directory = os.path.abspath(os.path.join(base, environ.get("UV_PROJECT") or ""))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check the desktop installer's default directory for uv configs

On an otherwise eligible Windows RTX 50-series installation with a mirror-configured %USERPROFILE%\.unsloth\uv.toml and no UV_PROJECT or working-directory override, this skips project discovery and recommends Repair even though Repair cannot take the managed 2.13 route. The desktop installer explicitly starts in the profile's .unsloth directory (studio/src-tauri/src/install.rs:627–642, process.rs:1876–1888), and install.ps1's Test-MirrorConfigured walks from that directory even without overrides, causing Test-PypiUnslothAdmitsTorch to reject the upgrade. Include discovery from the desktop installer's default working directory so users are not repeatedly sent through a reinstall that cannot resolve the recommendation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5e4e149: with USERPROFILE known, discovery starts from %USERPROFILE%.unsloth (the directory Desktop launches install.ps1 in) and walks up as Test-MirrorConfigured does; UV_WORKING_DIR and UV_PROJECT resolve against it. New test fails on 84ee157.

Desktop runs install.ps1 from %USERPROFILE%\.unsloth, and its mirror
check walks up from there even with no uv override set. Start there too,
so a mirror in that tree keeps the hint off when Repair cannot reach the
managed torch.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 5e4e149351

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 31f18d3 into main Nov 27, 2026
4 of 54 checks passed
@danielhanchen
danielhanchen deleted the g103-studio-repair-hint branch November 27, 2026 06:46
danielhanchen added a commit that referenced this pull request Nov 27, 2026
… fused-MPS-attention release on re-run (#20038)

## Problem

New Apple Silicon homes get torch 2.13 (#18428), because 2.13 is the
first release with the fused MPS prefill attention kernel. Studio only
enables that kernel on torch 2.13 or newer (`mps_prefill_supported` in
`diffusion_attention.py`). An existing home keeps whatever torch it has,
from 2.4 up to 2.14, unless the user sets `UNSLOTH_TORCH_UPGRADE=1`. So
every Mac that was installed before #18428 keeps its old torch and runs
diffusion on the math-only attention path.

On a MacBook Pro M5 Max with the same Studio backend and the same
prompts, warm time per 1024x1024 image was:

| Pipeline | torch 2.10.0 (that Mac's existing home) | torch 2.14.1 |
|---|---|---|
| FLUX.2 klein, bf16 | 8.60 s | 3.69 s |
| FLUX.2 klein, GGUF | 11.30 s | 6.39 s |
| Z-Image, GGUF | 64.37 s | 18.00 s |

Peak memory was also 3 to 5 GB lower on the newer torch. A large-linear
check showed no corruption on either version. The images are not
pixel-identical across versions, because the MPS random generator stream
changed between those releases. Within a single version, repeated runs
are bit-identical.

## Change

The change is in `install.sh`, on the macOS arm64 route only. On a
re-run, an existing home whose resident torch is a plain release below
`_MACOS_TORCH_MOVE_FLOOR` (2.13.0, the release Studio's fused MPS
attention gate needs) now takes the same `torch>=2.13.0,<2.14.0` /
`torchvision>=0.28.0,<0.29.0` constraint that a new home gets.
torchaudio resolves to 2.11.x, as it does on a new home. This happens
only when every gate of the new-install route already holds:

- the package is `unsloth`;
- the index is the default cpu index (an index set with
`UNSLOTH_TORCH_INDEX_URL` or `UNSLOTH_TORCH_INDEX_FAMILY` never moves);
- macOS 14 or later, with a GIL-enabled Python 3.10 to 3.14;
- the released `unsloth` on PyPI admits torch 2.13. An unreachable or
capped PyPI keeps the resident release.

These cases are unchanged:

- A home already on 2.13 or 2.14 is kept.
- A home whose torch cannot be read, or holds a nightly, takes the same
path as before.
- `UNSLOTH_TORCH_UPGRADE=0` (any value other than empty or `1`) keeps
the resident release.
- `UNSLOTH_TORCH_UPGRADE=1` behaves as before.

The move floor is its own literal, not derived from
`_MACOS_NEW_INSTALL_TORCH`. A later bump of the new-install pin (for
example to 2.14) therefore never moves a 2.13 home. Homes below 2.13
move to whatever the pin is at that point.

The installer prints `existing install has torch X -- moving to
torch>=2.13.0,<2.14.0 for the fused MPS attention kernel (set
UNSLOTH_TORCH_UPGRADE=0 to keep it)`.

This follows the rule the installer already uses for a raised floor
(#7250): a release below a route's floor is outside the preservation
window, so it moves. On ROCm 7.2 and Strix, that floor is 2.11. Here it
is 2.13.

Linux, WSL, Windows (`install.ps1` is untouched), Intel macOS, CUDA,
ROCm and XPU take exactly the same decisions as before. The new code
runs only inside the macOS arm64 branch, and the shared pin block skips
`_previous_torch_pin` only when that branch has decided to move.

### Why existing homes were preserved, and why this is safe on Apple
Silicon

- #6959 / #7250: a re-run should keep the torch release a user has
validated. The trigger was a silent 2.10 to 2.11 move on a CUDA host.
That still holds at or above 2.13 here.
- #12150: on CUDA, the torch release is tied to prebuilt flash-attn,
causal-conv1d and mamba-ssm wheels. `studio update` can also re-resolve
torch under an older release's cap. Apple Silicon has no such prebuilt
kernels. The PyPI gate is kept, and #18659 freezes the resident torch
through `studio update` on Apple Silicon, so a moved home stays on 2.13
there.
- torchcodec is chosen from the resident torch on every
`install_python_stack.py` pass, so it follows the move.
- A re-run rebuilds the venv anyway. A failed install rolls back to the
previous environment, unless `--no-rollback` was passed.

## Tests

- `tests/sh/test_macos_torch213_route.sh`: 132 checks. 22 fail on main.
3 more fail on a version of this branch that derived the floor from the
pin: the floor literal, and a pin bumped to 2.14 still keeping 2.13.0
and 2.13.1 homes.
- Existing 2.6 / 2.10 / 2.11 / 2.12.1 homes, and 2.10.0+cpu, move to the
2.13 constraint and announce the opt-out.
- These homes are kept: 2.13.0 / 2.13.1 / 2.14.0 / 2.14.1;
`UNSLOTH_TORCH_UPGRADE=0|false|no`; a pinned index; macOS 13;
free-threaded Python; Python 3.9; another `--package`; an unreachable or
capped PyPI.
- With the pin bumped to 2.14 in the test: 2.13.0 and 2.13.1 homes are
kept, and a 2.10 home moves to the bumped pin.
- These are unchanged: a nightly, a release under the window floor,
`--no-torch`, Intel macOS, and Linux / WSL / Windows on the cpu and
cu128 indexes.
- Unchanged and passing: `test_cu130_torch213_route.sh` (104),
`test_previous_torch_pin.sh` (50), `test_get_torch_index_url.sh` (109),
`test_torch_constraint.sh`, and
`tests/python/test_macos_torch213_pins.py`.
- Whole `tests/sh` suite: all 101 scripts pass on this branch, and all
of them pass on the merge base too (the base runs its own copy of the
route test).
- Workflow lints: `scripts/lint_workflow_triggers.py` and actionlint
pass. 58 test files read the workflow files: 3655 passed. The 2 failures
(`test_cached_paths_hold_no_credentials`, `test_version_compat_bundle`
daily sweep) fail the same way on the merge base, because of this host's
environment.

## Upgrade run on macOS 15

`.github/workflows/studio-mac-torch-floor-upgrade.yml` (helper
`.github/scripts/mac-torch-floor-upgrade.sh`) runs on macos-15 with
Python 3.13 and 3.10. It starts a home with the merge base installer and
moves it to torch 2.10.0 / torchvision 0.25.0 / torchaudio 2.10.0. Then
it checks:

- A: re-running the merge base installer keeps 2.10.
- B: re-running this branch's installer moves the home to 2.13.x /
0.28.x / 2.11.x, with MPS available and MPS attention matching an fp64
CPU reference.
- B2: a second re-run, then `unsloth studio update --local`, keep 2.13.
- C: `UNSLOTH_TORCH_UPGRADE=0` keeps a 2.10 home.
- D: a 2.14.1 home is kept.

The workflow runs on dispatch, and on pull requests only outside
`unslothai/unsloth`. On this repository's pull requests the job is
skipped, so it takes no macOS runner. It also skips drafts.

Results: pending.

## Not covered

- The Desktop automatic startup repair runs the installer without
`UNSLOTH_TORCH_UPGRADE`, so a repair of a home below 2.13 now moves it
to 2.13 as well. This is intended. Set `UNSLOTH_TORCH_UPGRADE=0` in the
environment to keep the resident torch.
- The Desktop app updates through `unsloth studio update`, which never
runs `install.sh`. A Desktop home that is never repaired or re-installed
keeps its torch. It moves through Settings > Repair installation, which
already sets `UNSLOTH_TORCH_UPGRADE=1`. Follow-up: a Studio "Repair
recommended" hint for Apple Silicon homes below 2.13, like the Windows
one in #19870.
- GitHub's macOS runners are virtual machines, so they show that the
install works, not how fast it runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant